<?php
namespace app\common\service;
use app\common\service\Material as MaterialService;
use app\common\service\StallCost as StallCostService;
use app\common\service\Base;
class StallFeed extends Base
{
	/**
	 * 根据ID获取记录信息
	 *
	 * @author 飞燕
	 * @date 2021年3月16日
	 *
	 * @param integer $id
	 * @param string $field
	 * @return array
	 */
	public function getInfoById($id, $field='*') {
		if (empty($id)) return [];
		$materialService=new MaterialService();
		$stallCostService=new StallCostService();
		$info = db('stall_feed')->where('id', $id)->field($field)->findOrEmpty();
		if ($info && isset($info['material_id'])) {
			$info['mInfo'] = db('order_material om')
                ->join('material m', "om.material_id=m.id", 'left')
                ->where('order_id', $info['order_id'])->where('material_id', $info['material_id'])->field("m.*,om.customer_price as customer_price ")->findOrEmpty();
		}
		if ($info) {
			$info['scInfo'] = $stallCostService->getListByStallFeedId($id);
		}
		return $info;
	}
	/**
	 * 根据order_material_id获取列表
	 *
	 * @author 飞燕
	 * @date 2021年5月20日
	 *
	 * @param integer $orderMaterialId
	 * @param string $field			需要显示的字段
	 * @return array
	 */
	public function getListByMid($mid, $field='*') {
		if (empty($mid)) return [];
		$where = [
			['order_material_id', '=', $mid],
		];
		return db('stall_feed')->where($where)->field($field)->order('id asc')->select();
	}
}
